﻿
using Base.WCS.Common;
using Base.WCS.Entity;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
 namespace Base.ClientUI {
    public class HttpTaskUtil
    {
        static public List<Complete> getComplete() {
            JArray data = WCSHttpUtil.getArray(WCSHttpUtil.baseUrl + "Task/getComplete");
            if(data == null) {
                return null;
                ;
            }
            List <Complete> list= JsonConvert.DeserializeObject<List<Complete>>(data.ToString());
            return list;
        }
         static public bool UpdateTaskPriorityByCompleteId(long completeId)
        {
            JValue data = WCSHttpUtil.getJValue(WCSHttpUtil.baseUrl + "Task/UpdateTaskPriorityByCompleteId/" + completeId);
             if (data == null)
            {
                return false;
            }
            return bool.Parse(data.ToString());
        }
        static public List<CompleteParam> GetCompleteParam(long id)
        {
            JArray data = WCSHttpUtil.getArray(WCSHttpUtil.baseUrl + "Task/GetCompleteParam/"+id);
            if (data == null)
            {
                return null;
                ;
            }
            List<CompleteParam> list = JsonConvert.DeserializeObject<List<CompleteParam>>(data.ToString());
            return list;
        }
         static public bool resetTaskById(string deviceType ,long taskId) {
            JValue data = WCSHttpUtil.getJValue(WCSHttpUtil.baseUrl + "Task/resetTask/" + deviceType + "/" + taskId);
            if( data == null ) {
                return false;
            }
            return bool.Parse(data.ToString());
        }
         static public string finishTaskById(string stn,long taskNo) {
            JValue data = WCSHttpUtil.getJValue(WCSHttpUtil.baseUrl + "Task/finishTask/"+ stn + "/" + taskNo);
            if( data == null ) {
                return "网络异常";
            }
            return data.ToString();
        }
         static public JObject getAllTaskByCompleteId(long taskId) {
             return WCSHttpUtil.getObject(WCSHttpUtil.baseUrl + "Task/getAllTaskByCompleteId/"  + taskId);
          
        }

        static public JObject updatePriority(long taskId)
        {
            return WCSHttpUtil.getObject(WCSHttpUtil.baseUrl + "Task/updatePriority/" + taskId);

        }
        static public bool DeleteCraneAndCarrierTask(long taskNo) {
            JValue data = WCSHttpUtil.getJValue(WCSHttpUtil.baseUrl + "Task/DeleteCraneAndCarrierTask/" + taskNo);
            if( data == null ) {
                return false;
            }
            return bool.Parse(data.ToString());
        }

        static public string move(string src,string des) {
            int s = int.Parse(src);
            int d = int.Parse(des);
            JValue data = WCSHttpUtil.getJValue(WCSHttpUtil.baseUrl + "Task/move/" + s+"/"+ d);
            if( data == null ) {
                return "发送异常";
            }
            return data.ToString();
        }
    }
}
